package com.ly.mpayment.persist.service.blacklist;

import com.ly.mpayment.persist.entity.BlackList;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class BlackListServiceImpl extends AbstractService<BlackList, Serializable>  implements IBlackListService {

	@Override
	public BlackList findPhone(String phone) {
		return this.findUnique("select m from BlackList m where m.phone = ?", phone);
	}

	@Override
	public boolean saveBlackList(BlackList weiliu) {
		if(weiliu != null){
			this.save(weiliu);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateBlackList(BlackList weiliu) {
		if(weiliu != null){
			this.updateEntity(weiliu);
			return true;
		}
		return false;
	}

	/**
	 * private String phone;
		private String province;
		private String city;
	 */
	@Override
	public Page<BlackList> findPageBlackList(Map<String, Object> parameters, int start, int pageSize) {
		String hql = "select m from BlackList m where 1=1 #[ and m.phone like :phone]#  order by m.phone asc";
		return this.findPageByNamed(hql, parameters, start, pageSize);
	}

	@Override
	public BlackList findById(String id) {
		return this.findUnique("select m from BlackList m where m.id = ?", id);
	}

	@Override
	public List<BlackList> findAllCityIsnull(boolean temp) {
		String sql = temp ? "select m from BlackList m where m.phone is null" : "select m from BlackList m where m.phone = ''";
		return this.find(sql);
	}

	@Override
	public boolean deleteForm(BlackList mobile) {
		  this.delete(mobile);
		return true;
	}
}
